package 贪心;

/**
 * @ClassName _45跳跃游戏II
 * @Description TODO
 * @Author 昝亚杰
 * @Date 2021/12/13 20:00
 * Version 1.0
 **/
public class _45跳跃游戏II {
    public int jump(int[] nums) {
        if(nums == null || nums.length == 0 || nums.length == 1){
            return 0;
        }
        int coverange = 0,step = 0,maxcoverage = 0;
        for(int i = 0; i < nums.length; i++){
            maxcoverage = i + nums[i] > maxcoverage ? i + nums[i] : maxcoverage;
            if(maxcoverage >= nums.length - 1){
                step++;
                break;
            }
            if(i == coverange){
                coverange = maxcoverage;
                step++;
            }
        }

        return step;
    }
}
